/**
 * 包含管理员信息、外部应用信息的 User 模型
 * @param app
 * @returns {*}
 */
module.exports = app => {
  const mongoose = app.mongoose
  const { Schema } = mongoose
  const { ObjectId } = Schema

  const modelSchema = new Schema({
    name: { type: String, remark: '用户名', required: true },
    password: { type: String, required: true, remark: '密码' },
    email: { type: String, remark: '邮箱' },
    isAdmin: { type: Boolean, default: false, required: true, remark: '是否是管理员' },
    session: { type: String, remark: '用户 session' },
  }, {
    collections: 'user',
    timestamps: true,
  })

  modelSchema.index({ name: 1 }, { unique: true })
  modelSchema.index({ password: 1 })

  return mongoose.model('user', modelSchema)
}